<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>3D窗帘可视化</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        body {
            margin: 0;
            overflow: hidden;
            font-family: "Arial", sans-serif;
            color: #333;
            display: flex;
            flex-direction: column;
            align-items: center;
            box-sizing: border-box;
            background: #ffffff;
        }

        .container {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 100%;
            max-width: 600px;
            justify-content: center;
            height: 400px;
            box-sizing: border-box;
        }

        #scene-container {
            width: 100%;
            max-width: 600px;
            height: 400px;
            border: 2px solid rgba(0, 0, 0, 0.1);
            border-radius: 8px;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
            box-sizing: border-box;
        }

        @media (max-width: 600px) {
            #scene-container {
                height: 350px;
            }

            .container {
                justify-content: flex-start;
                padding-top: 20px;
            }
        }
    </style>

    <!-- <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/build/three.min.js"></script> -->
    <script src="./js/three.min.js"></script>
    <!-- <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/loaders/RGBELoader.js"></script> -->
    <script src="./js/RGBELoader.js"></script>
    <!-- <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/controls/OrbitControls.js"></script> -->
    <script src="./js/OrbitControls.js"></script>
    <!-- <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/loaders/OBJLoader.js"></script> -->
    <script src="./js/OBJLoader.js"></script>
    <!-- <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/loaders/MTLLoader.js"></script> -->
    <script src="./js/MTLLoader.js"></script>


    <!-- 引入websocket模块 -->
    <script src="./js/module/websocket.js"></script>

    <!-- 引入three.js模块 -->
    <script src="./js/module/initThree.js"></script>

    <!-- 引入窗帘模块 -->
    <script src="./js/module/curtain.js"></script>

    <!-- 导入base64变量 -->
    <script src="./js/url.js"></script>

    <!-- 引入灯光模块 -->
    <script src="./js/module/light.js"></script>
</head>

<body>
    <div class="container">
        <div id="scene-container"></div>
    </div>

    <script>


        function onWindowResize() {
            const container = document.getElementById("scene-container");
            camera.aspect = container.clientWidth / container.clientHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(container.clientWidth, container.clientHeight);
        }

        function animate() {
            requestAnimationFrame(animate);
            controls.update();
            renderer.render(scene, camera);
        }



        function updateUI(state) {
            const position = state.attributes.current_position ?? (state.state === "open" ? 100 : 0);
            curtainAssemblyArray.forEach((item) => {
                updateCurtain(item.params, position, item.value);
            })

        }

        window.onload = () => {
            initThreeJS();
            connectWebSocket();
        };
    </script>
</body>

</html>